/**
 * Created by a1 on 2017/10/16.
 */
"use strict";
var BookModel = require('../models/Book.js');//书本Schema
var AutoplayModel = require('../models/Autoplay.js');
//轮播图Schema

exports.getautoPlay=function(req,res){
    AutoplayModel.findFn({},{"apid":1},function(err,docs){
        if(err){
            res.json({msg:'失败',code:0,info:[]});
        }
        res.json({msg:'成功',code:1,info:docs});
    });
};
exports.getrmxsBook=function(req,res){
    BookModel.findFnLimit({},{"clickCnt":-1},7,function(err,docs){
        if(err){
            res.json({msg:'失败',code:0,info:[]});
        }
        res.json({msg:'成功',code:1,info:docs});
    });
};
exports.getrxbBook=function(req,res){
    BookModel.findFnLimit({},{"reward":-1},7,function(err,docs){
        if(err){
            res.json({msg:'失败',code:0,info:[]});
        }
        res.json({msg:'成功',code:1,info:docs});
    });
};
exports.getfybBook=function(req,res){
    BookModel.findFnLimit({},{"recomendCnt":-1},7,function(err,docs){
        if(err){
            res.json({msg:'失败',code:0,info:[]});
        }
        res.json({msg:'成功',code:1,info:docs});
    });
};
exports.getypbBook=function(req,res){
    BookModel.findFnLimit({},{"month":-1},7,function(err,docs){
        if(err){
            res.json({msg:'失败',code:0,info:[]});
        }
        res.json({msg:'成功',code:1,info:docs});
    });
};
exports.gettjbBook=function(req,res){
    BookModel.findFnLimit({},{"recomm":-1},7,function(err,docs){
        if(err){
            res.json({msg:'失败',code:0,info:[]});
        }
        res.json({msg:'成功',code:1,info:docs});
    });
};
exports.getxsqxBook=function(req,res){
    BookModel.findFnLimit({"cnt":{$lte:1000000},"clickCnt":{$gte:1000}},{"clickCnt":-1},3,function(err,docs){
        if(err){
            res.json({msg:'失败',code:0,info:[]});
        }
        res.json({msg:'成功',code:1,info:docs});
    });
};
exports.getqxwbBook=function(req,res){
    BookModel.findFnLimit({"stateType":"F","subscribe":{$gte:100}},{"subscribe":-1},3,function(err,docs){
        if(err){
            res.json({msg:'失败',code:0,info:[]});
        }
        res.json({msg:'成功',code:1,info:docs});
    });
};
exports.getxsmfBook=function(req,res){
    BookModel.findConut({},function(err,count){
        let ran=parseInt(Math.random()*count+1);
        BookModel.findFnLimit({"bid":{$gte:0}},{"bid":1},7,function(err,docs){
            if(err){
                res.json({msg:'失败',code:0,info:[]});
            }
            res.json({msg:'成功',code:1,info:docs});
        });
    });
};
exports.getxhqhBook=function(req,res){
    BookModel.findFnLimit({$or:[{catId:1},{catId:2}]},{"reward":-1},6,function(err,docs){
        if(err){
            res.json({msg:'失败',code:0,info:[]});
        }
        res.json({msg:'成功',code:1,info:docs});
    });
};
exports.getxxwxBook=function(req,res){
    BookModel.findFnLimit({$or:[{catId:3},{catId:4}]},{"reward":-1},6,function(err,docs){
        if(err){
            res.json({msg:'失败',code:0,info:[]});
        }
        res.json({msg:'成功',code:1,info:docs});
    });
};
exports.getdszcBook=function(req,res){
    BookModel.findFnLimit({$or:[{catId:5},{catId:6}]},{"reward":-1},6,function(err,docs){
        if(err){
            res.json({msg:'失败',code:0,info:[]});
        }
        res.json({msg:'成功',code:1,info:docs});
    });
};
exports.getlsjsBook=function(req,res){
    BookModel.findFnLimit({$or:[{catId:7},{catId:8}]},{"reward":-1},6,function(err,docs){
        if(err){
            res.json({msg:'失败',code:0,info:[]});
        }
        res.json({msg:'成功',code:1,info:docs});
    });
};
exports.getyxtyBook=function(req,res){
    BookModel.findFnLimit({$or:[{catId:9},{catId:10}]},{"reward":-1},6,function(err,docs){
        if(err){
            res.json({msg:'失败',code:0,info:[]});
        }
        res.json({msg:'成功',code:1,info:docs});
    });
};
exports.getkhlyBook=function(req,res){
    BookModel.findFnLimit({$or:[{catId:11},{catId:12}]},{"reward":-1},6,function(err,docs){
        if(err){
            res.json({msg:'失败',code:0,info:[]});
        }
        res.json({msg:'成功',code:1,info:docs});
    });
};
exports.getecyBook=function(req,res){
    BookModel.findFnLimit({$or:[{catId:13}]},{"reward":-1},7,function(err,docs){
        if(err){
            res.json({msg:'失败',code:0,info:[]});
        }
        res.json({msg:'成功',code:1,info:docs});
    });
};